//
//  DDateAnalysisHeaderView.swift
//  Drop
//
//  Created by hushaohua on 2018/8/4.
//  Copyright © 2018年 init. All rights reserved.
//

import UIKit

class DDateAnalysisHeaderView: UIView {

    override init(frame: CGRect) {
        super.init(frame: frame);
        self.addSubview(self.chartTypeControl);
        self.chartTypeControl.selectedSegmentIndex = 0;
//        self.configMask();
    }
    
    func configMask(){
        let view:UIView = UIView(frame: self.bounds);
        view.backgroundColor = UIColor.black;
        view.alpha = 0;
        self.mask = view;
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    lazy var chartTypeControl:UISegmentedControl = {
        let font:UIFont = UIFont(name: "iconfont", size: 22)!;
        let selectedColor = UIColor.white;
        let normalColor = UIColor.rgbColor(0xfb, 0x4b, 0x0e);
        var control = UISegmentedControl(items: ["\u{e663}","\u{e670}","\u{e62d}"])
        control.tintColor = normalColor;
        control.frame = CGRect(x:15,y:10,width:180,height:32);
        control.setTitleTextAttributes([NSAttributedStringKey.font : font, NSAttributedStringKey.foregroundColor : normalColor], for: .normal);
        control.setTitleTextAttributes([NSAttributedStringKey.font : font, NSAttributedStringKey.foregroundColor : selectedColor], for: .selected);
        control.addTarget(self, action: #selector(chartTypeChanged(_:)), for: .valueChanged);
        return control;
    }();
    
    var chartTypeChangedClosure:((DisplayChartType) -> (Void))?;
    @objc func chartTypeChanged(_ control:UISegmentedControl){
        self.chartType = DisplayChartType(rawValue: control.selectedSegmentIndex)!;
        if (self.chartTypeChangedClosure != nil){
            self.chartTypeChangedClosure!(self.chartType);
        }
    }
    
    enum DisplayChartType:Int {
        case text = 0
        case bar = 1
        case pie = 2
    }
    var chartType:DisplayChartType = .text;


}
